﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using StructureMap;
using StructureMap.Configuration;
using StructureMap.Configuration.DSL;

namespace ContactManager.Models.Validation
{
    public class ValidationService : IValidationService
    {
        #region IValidationService Members

        public IValidator<TEntity> GetValidatorFor<TEntity>(TEntity entity)
        {
            return ObjectFactory.GetInstance<IValidator<TEntity>>();
        }

        public ValidationState Validate<TEntity>(TEntity entity)
        {
            IValidator<TEntity> validator = GetValidatorFor(entity);

            if (validator == null)
            {
                throw new Exception("Cannot locate validator");
            }

            return validator.Validate(entity);
        }

        #endregion 

    }
}
